home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / MacODBC / ODBC Tools / SampleTranslate / Sources / ODBCdataTranslate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-27  |  4.7 KB  |  226 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    ODBCdataTranslate.c
  3.  *
  4.  *    (c) Apple Computer, Inc 1993
  5.   *    (c) Visigenic Software, Inc 1995
  6. *
  7.  *    changes:
  8.  *
  9.  *    1.0a1    -    removed all calls to OpenGlobalWorld, as this is compiled model far
  10.  *                and doesn't have any A5-relative references to globals. Also
  11.  *                removed code to set up the QuickDraw environment, e.g. calls to 
  12.  *                InitGraf, etc., as these should not be done more than once from a process.
  13.  *                A5 world is assumed to have valid QD globals when this shared library is called.
  14.  */
  15.  
  16. #include <Dialogs.h>
  17. #include <Fonts.h>
  18. #if ! PPCODBC
  19. #include <LibraryManagerUtilities.h>
  20. #endif // ! PPCODBC
  21. #include <Menus.h>
  22. #include <OSUtils.h>
  23. #include <QuickDraw.h>
  24. #include <TextEdit.h>
  25. #include <Windows.h>
  26.  
  27. #include "ODBCSharedLibraries.h"
  28. #include "DataTran.h"
  29.  
  30. #include "ConfigTranslator.h"
  31.  
  32. /*
  33.  *    Prototypes
  34.  */
  35.  
  36. /*
  37.  *    Public functions
  38.  */
  39.  
  40. #if PPCODBC
  41.  
  42. #include <Memory.h>
  43. #include <Errors.h>
  44.  
  45. Handle hinst;
  46.  
  47. // _____________________________________________________________________________
  48.     OSErr
  49.     SampleTranslateInit( InitBlockPtr ib )
  50. {
  51.     /*
  52.      *    shared library init function.  All shared libraries should have one.  Its name is
  53.      *    declared in the .exp file.
  54.      */
  55.  
  56.     if ( ib->fragLocator.where != kOnDiskFlat ) { return -32323; }
  57.     
  58.     hinst = NewHandle( sizeof( ODBCLibConnection ) );
  59.     if ( ! hinst ) { return memFullErr; }
  60.     HLock( hinst );
  61.     
  62.     (*(ODBCLibConnection**)hinst)->spec = *ib->fragLocator.u.onDisk.fileSpec;
  63.     (*(ODBCLibConnection**)hinst)->connId = ib->connectionID;
  64.     
  65.     HUnlock( hinst );
  66. }
  67.  
  68.  
  69. // _____________________________________________________________________________
  70.     extern "C"
  71.     void 
  72.     SampleTranslateMain( HINSTANCE hinst2init )
  73. {
  74.     HLock( hinst );
  75.     HLock( hinst2init );
  76.     **(ODBCLibConnection**)hinst2init = **(ODBCLibConnection**)hinst;
  77.     HUnlock( hinst );
  78.     HUnlock( hinst2init );
  79. }
  80.  
  81.  
  82. #else  // PPCODBC
  83.  
  84. // _____________________________________________________________________________
  85.     void
  86.     SampleTranslateInit()
  87. {
  88.     /*
  89.      *    shared library init function.  All shared libraries should have one.  Its name is
  90.      *    declared in the .exp file.
  91.      */
  92.  
  93.     // note: hinst is not needed for the 68k ODBCSharedLibraries functions
  94. }
  95.  
  96. #endif // PPCODBC
  97.  
  98. // _____________________________________________________________________________
  99.     void
  100.     SampleTranslateObit()
  101. {
  102.     /*
  103.      *    Shared library cleanup function.  All shared libraries should have one.  Its name is
  104.      *    declared in the .exp file.
  105.      */
  106.      
  107. #if PPCODBC
  108.     DisposHandle( hinst );
  109. #endif // PPCODBC
  110. }
  111.  
  112. TRANSPREAPI BOOL TRANSAPI
  113. ConfigTranslator(GrafPtr    pGrafPort,            /* window to center over    */
  114.                  DWORD        *pvOption)            /* translation option        */
  115. {
  116.     /*
  117.      *    Shared lilbrary entry point for configuring a data translator.
  118.      */
  119.     
  120.     BOOL                success;
  121.     ODBCLibResContext    context;
  122.     
  123.     if ( ODBCLibUseLocalRes( &context ) )
  124.     {
  125.         SysBeep(1);    // can't put up our alert if ODBCLibUseLocalRes failed
  126.         return FALSE;
  127.     }
  128.     
  129.     /*
  130.      *    do the work
  131.      */
  132.     
  133.     success = (BOOL) DoConfigTranslator((WindowPtr) pGrafPort, pvOption);
  134.     
  135.     /*
  136.      *    restore resource path, A5 world
  137.      */
  138.     
  139.     ODBCLibCloseLocalRes( &context );
  140.     
  141.     return success;
  142. }
  143.  
  144. TRANSPREAPI BOOL TRANSAPI
  145. SQLDataSourceToDriver(UDWORD    fOption,
  146.                       SWORD        fCType,
  147.                       PTR        rgbValueIn,
  148.                       SDWORD    cbValueIn,
  149.                       PTR        rgbValueOut,
  150.                       SDWORD    cbValueOutMax,
  151.                       SDWORD    *pcbValueOut,
  152.                       UCHAR        *szErrorMsg,
  153.                       SWORD        cbErrorMsgMax,
  154.                       SWORD        *pcbErrorMsg)
  155. {
  156. #pragma unused(    fOption, fCType, rgbValueIn, cbValueIn, rgbValueOut, cbValueOutMax, pcbValueOut, szErrorMsg, cbErrorMsgMax, pcbErrorMsg )
  157.     /*
  158.      *    Shared lilbrary entry point for SQLDataSourceToDriver.
  159.      */
  160.     
  161.     BOOL                success;
  162.     ODBCLibResContext    context;
  163.     
  164.     if ( ODBCLibUseLocalRes( &context ) )
  165.     {
  166.         SysBeep(1);    // can't put up our alert if ODBCLibUseLocalRes failed
  167.         return FALSE;
  168.     }
  169.     
  170.     /*
  171.      *    here's where the work gets done
  172.      */
  173.     
  174.     success = TRUE;    // your code goes here
  175.     
  176.     /*
  177.      *    restore resource path, A5 world
  178.      */
  179.     
  180.     ODBCLibCloseLocalRes( &context );
  181.     
  182.     return success;
  183. }
  184.  
  185. TRANSPREAPI BOOL TRANSAPI
  186. SQLDriverToDataSource(UDWORD    fOption,
  187.                       SWORD        fCType,
  188.                       PTR        rgbValueIn,
  189.                       SDWORD    cbValueIn,
  190.                       PTR        rgbValueOut,
  191.                       SDWORD    cbValueOutMax,
  192.                       SDWORD    *pcbValueOut,
  193.                       UCHAR        *szErrorMsg,
  194.                       SWORD        cbErrorMsgMax,
  195.                       SWORD        *pcbErrorMsg)
  196. {
  197. #pragma unused(    fOption, fCType, rgbValueIn, cbValueIn, rgbValueOut, cbValueOutMax, pcbValueOut, szErrorMsg, cbErrorMsgMax, pcbErrorMsg )
  198.     /*
  199.      *    Shared lilbrary entry point for SQLDriverToDataSource.
  200.      */
  201.     
  202.     BOOL                success;
  203.     ODBCLibResContext    context;
  204.     
  205.     if ( ODBCLibUseLocalRes( &context ) )
  206.     {
  207.         SysBeep(1);    // can't put up our alert if ODBCLibUseLocalRes failed
  208.         return FALSE;
  209.     }
  210.     
  211.     /*
  212.      *    here's where the work gets done
  213.      */
  214.     
  215.     success = TRUE;    // your code goes here
  216.     
  217.     /*
  218.      *    restore resource path, A5 world
  219.      */
  220.     
  221.     ODBCLibCloseLocalRes( &context );
  222.     
  223.     return success;
  224. }
  225.  
  226.